<template>
  <div class="base-echart">
    <div ref="baseEchartRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref, watchEffect } from 'vue'
import { useEchart } from '@/base-ui/echart/hooks/use-echart'

export default defineComponent({
  setup(props) {
    const baseEchartRef = ref()
    onMounted(() => {
      const { setOptions } = useEchart(baseEchartRef.value)
      watchEffect(() => {
        setOptions(props.options)
      })
    })
    return {
      baseEchartRef
    }
  },
  props: {
    options: {
      type: Object,
      required: true
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '360px'
    }
  }
})
</script>
